#include <string>
#include <fstream>
#include <vector>

unsigned const __int64 MOD = 1000000007;

struct node;
class aut;

struct node
{
    bool terminal, usefull;
    node * * next;
    std::vector<node *> prev;
    unsigned number;
    node():
    terminal(false), next(0), usefull(false), number(0), prev()
    {
             
    }
};

class aut
{
    unsigned n_, alph_size_;
    char f_, l_;
    node * nodes_;
    unsigned char_number_(char);
    bool top_sort_(node *, node * *, unsigned *, unsigned&);
    void spread_us_(node *);
public:
    aut(char, char);
    friend std::ifstream& operator >> (std::ifstream&, aut&);
    std::string check(std::string&);
    int words_count();
};

bool aut::top_sort_(node * cur, node * * ord, unsigned * status, unsigned& vcount)
{
    status[cur->number] = 1;
    for (unsigned i = 0; i < alph_size_; ++i)
    {
        if (cur->next[i] && cur->next[i]->usefull)
        {
            if (status[cur->next[i]->number] == 1)
            {
                return true;
            }
            else
            {
                if (status[cur->next[i]->number] == 0)
                {
                    if (top_sort_(cur->next[i], ord, status, vcount))
                    {
                        return true;
                    }
                }
            }
        }
    }
    status[cur->number] = 2;
    ord[++vcount] = cur;
    return false;
}

void aut::spread_us_(node * cur)
{
    for (std::vector<node *>::iterator i = cur->prev.begin(); i != cur->prev.end(); ++i)
    {
        if (!(*i)->usefull)
        {
            (*i)->usefull = true;
            spread_us_((*i));
        }
    }
}

int aut::words_count()
{
    int ans;
    for (unsigned i = 1; i <= n_; ++i)
    {
        if (nodes_[i].terminal)
        {
            spread_us_(nodes_ + i);
        }
    }
    if (!nodes_[1].usefull)
        ans = 0;
    else
    {
        node * * ord = new node * [n_ + 1];
        unsigned * status = new unsigned[n_ + 1];
        memset(status, 0, (n_ + 1) * sizeof(unsigned));
        unsigned vcount(0);
        if (top_sort_(nodes_ + 1, ord, status, vcount))
        {
            ans = -1;
        }
        else
        {
            unsigned * pcount = new unsigned[n_ + 1];
            memset(pcount, 0, (n_ + 1) * sizeof(unsigned));
            pcount[1] = 1;
            for (unsigned i = vcount; i > 0; --i)
            {
                for (unsigned j = 0; j < alph_size_; ++j)
                {
                    if (ord[i]->next[j])
                    {
                        pcount[ord[i]->next[j]->number] = (pcount[ord[i]->next[j]->number] + pcount[ord[i]->number]) % MOD;
                    }
                }
            }
            ans = 0;
            for (unsigned i = 1; i <= n_; ++i)
            {
                if (nodes_[i].terminal)
                {
                    ans = (ans + pcount[i]) % MOD;
                }
            }
        }
    }
    return ans;
}

unsigned aut::char_number_(char c)
{
    return c - f_;
}

aut::aut(char f, char l):
f_(f), l_(l), alph_size_(l - f + 1)
{
    
}

std::ifstream& operator >> (std::ifstream& in, aut& a)
{
    unsigned n, m, k, b, d;
    char c;
    in >> n >> m >> k;
    a.nodes_ = new node[n + 1];
    a.n_ = n;
    for (unsigned i = 1; i <= n; ++i)
    {
        a.nodes_[i].number = i;
        a.nodes_[i].next = new node * [a.alph_size_];
        for (unsigned j = 0; j < a.alph_size_; ++j)
        {
            a.nodes_[i].next[j] = 0;
        }
    }
    for (unsigned i = 0; i < k; ++i)
    {
        in >> d;
        a.nodes_[d].terminal = true;
        a.nodes_[d].usefull = true;
    }
    for (unsigned i = 0; i < m; ++i)
    {
        in >> b >> d >> c;
        a.nodes_[b].next[a.char_number_(c)] = a.nodes_ + d;
        a.nodes_[d].prev.push_back(a.nodes_ + b);
    }
    return in;
}

std::string aut::check(std::string& s)
{
    node * cur = nodes_ + 1;
    for (unsigned i = 0, l = s.length(); i < l && cur; ++i)
    {
        cur = cur->next[char_number_(s[i])];
    }
    if (!cur || !cur->terminal)
        return std::string("Rejects");
    else
        return std::string("Accepts");
}

int main()
{
    std::ifstream in("problem3.in");
    std::ofstream out("problem3.out");
    aut a('a', 'z');
    in >> a;
    out << a.words_count();
    return 0;
}